﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace OkTool.Util
{
    public class ObjectUtil
    {
        /// <summary>
        /// 是否为空,支持字符串,字典,list,array
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsEmpty(object obj)
        {
            if (obj == null) return true;
            if (obj is string)
            {
                return StrUtil.IsEmpty((string)obj);
            }
            else if (obj is Dictionary<object, object>)
            {
                return DictionaryUtil.IsEmpty((Dictionary<object, object>)obj);
            }
            else if (obj is List<object>)
            {
                return CollUtil.IsEmpty((List<object>)obj);
            }
            else if (obj is Array)
            {
                return ArrayUtil.IsEmpty((Array)obj);
            }

            return false;
        }

        /// <summary>
        /// 是否不为空
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool IsNotEmpty(object obj)
        {
            return IsEmpty(obj) == false;
        }


        /// <summary>
        /// 是否相等
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="obj2"></param>
        /// <returns></returns>
        public static bool Equal(object obj1, object obj2)
        {
            if (obj1.GetType().IsValueType && obj2.GetType().IsValueType)
            {
                return Equals(ConvertUtil.ToDecimal(obj1), ConvertUtil.ToDecimal(obj2));
            }
            return Equals(obj1, obj2);
        }
    }
}
